package network.course6.bytebuf.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import network.course6.bytebuf.model.Dog;

public class ServerObjectHandler extends ChannelInboundHandlerAdapter {
    public void exceptionCaught(ChannelHandlerContext ctx,Throwable cause){
        cause.printStackTrace();
        ctx.close();
    }
    public void channelRead(ChannelHandlerContext ctx,Object msg){
        //具体处理客户端的数据信息
        Dog dog=(Dog) msg;
        System.out.println("receive message. name=" + dog.getName() + ",type=" + dog.getType() + ",color=" + dog
                .getColor());
        //返回给客户端一个新的对象
        Dog returnDog=new Dog();
        returnDog.setName("jd");
        returnDog.setColor("black");
        returnDog.setType("阿拉斯加");
        ctx.writeAndFlush(returnDog);

    }
}
